﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace bomberbide
{
    public class camera
    {
        private int _x;

        public int x
        {
            get { return _x; }
            set { _x = value; }
        }
        private int _y;

        public int y
        {
            get { return _y; }
            set { _y = value; }
        }
        private float _zoom;

        public float zoom
        {
            get { return _zoom; }
            set { _zoom = value; }
        }
        private SpriteBatch _spriteBatch;

        public SpriteBatch spriteBatch
        {
            get { return _spriteBatch; }
            set { _spriteBatch = value; }
        }
        private PrimitiveBatch _primitive;

        public PrimitiveBatch primitiveBatch
        {
            get { return _primitive; }
            set { _primitive = value; }
        }
        private Texture2D _dot;

        public Texture2D dot
        {
            get { return _dot; }
            set { _dot = value; }
        }

        private Texture2D _carre;

        public Texture2D carre
        {
            get { return _carre; }
            set { _carre = value; }
        }
        private SpriteFont _font;

        public SpriteFont font
        {
            get { return _font; }
            set { _font = value; }
        }





        public float agrandissement()
        {
            return 1 / this.zoom;
        }
        public Vector2 mouse_position()
        {
            return new Vector2(
                this.x + Mouse.GetState().X / this.zoom,
                this.y + Mouse.GetState().Y / this.zoom);
        }


        public camera(SpriteBatch spriteBatch, PrimitiveBatch primitive)
        {
            this.x = 0;
            this.y = 0;
            this.zoom = 1;
            this.spriteBatch = spriteBatch;
            this.primitiveBatch = primitive;
        }
        public void Draw(Texture2D texture, Rectangle rectangle, Color couleur)
        {
            rectangle.X = (int)((rectangle.X - this.x) * this.zoom);
            rectangle.Y = (int)((rectangle.Y - this.y) * this.zoom);
            rectangle.Width = (int)(rectangle.Width * zoom);
            rectangle.Height = (int)(rectangle.Height * zoom);
            this.spriteBatch.Draw(texture, rectangle, couleur);
        }
        public void DrawTriangle(Vector2 A, Vector2 B, Vector2 C, Color couleur)
        {
            this.primitiveBatch.Begin(PrimitiveType.TriangleList);
            this.primitiveBatch.AddVertex((A - new Vector2(this.x, this.y)) * this.zoom, couleur);
            this.primitiveBatch.AddVertex((B - new Vector2(this.x, this.y)) * this.zoom, couleur);
            this.primitiveBatch.AddVertex((C - new Vector2(this.x, this.y)) * this.zoom, couleur);
            this.primitiveBatch.End();
        }
        public void DrawLine(Vector2 A, Vector2 B, Color couleur)
        {
            this.primitiveBatch.Begin(PrimitiveType.LineList);
            this.primitiveBatch.AddVertex((A - new Vector2(this.x, this.y)) * this.zoom, couleur);
            this.primitiveBatch.AddVertex((B - new Vector2(this.x, this.y)) * this.zoom, couleur);
            this.primitiveBatch.End();
        }
    }
}
